using System;
using System.Collections;
using NUnit.Framework;
using ValidationFramework.Configuration;
using ValidationFramework.Extensions;

namespace ValidationFramework.Tests.Configuration
{
    [TestFixture]
    public class LengthCollectionRuleConfigReaderTest
    {
        #region Methods

      [Test]
      public void ReadConfig()
      {
          const string validatorXml = "<rule errorMessage='hello' excludeDuplicatesFromCount='true' ruleSet='foo' typeName='LengthCollectionRule' minimum='1' maximum='5' equalityComparerTypeName='System.StringComparer' equalityComparerPropertyName='OrdinalIgnoreCase'/>";
          var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
        var rule = (LengthCollectionRule)ConfigurationService.GetRule(ruleData, typeof(IList).TypeHandle);
        Assert.AreEqual("hello", rule.ErrorMessage);
        Assert.AreEqual(true, rule.ExcludeDuplicatesFromCount);
        Assert.AreEqual(1, rule.Minimum);
        Assert.AreEqual(5, rule.Maximum);
        Assert.AreEqual(StringComparer.OrdinalIgnoreCase, rule.Comparer);


      }
      [Test]
      public void ReadConfigSimple()
      {
          const string validatorXml = "<rule typeName='LengthCollectionRule' maximum='5'/>";
          var ruleData = (RuleData.Read(validatorXml.ToXmlReader()));
        var rule = (LengthCollectionRule)ConfigurationService.GetRule(ruleData, typeof(IList).TypeHandle);
        Assert.AreEqual(null, rule.ErrorMessage);
        Assert.AreEqual(true, rule.ExcludeDuplicatesFromCount);
        Assert.AreEqual(0, rule.Minimum);
        Assert.AreEqual(5, rule.Maximum);
        Assert.AreEqual(null, rule.Comparer);


      }

        #endregion

    }
}